<?php

namespace app\modules\setting\configs\seller;

use app\common\enum\ConfigEnum;
use app\common\enum\EtcSellerTiktokProduct_shStatusEnum;
use app\common\enum\FormEnum;
use sookie\excel\SaveExcel;
use yii\db\ActiveRecord;
use sookie\react\handlers\UrlHandler;
use yii\helpers\ArrayHelper;
use yii\helpers\Json;
use app\modules\setting\models\seller\EtcSellerTiktokProduct;
use sookie\bootstraps\handlers\AuthChecker;

/**
* Class TestConfig
* @package sookie\react\configs
* app\modules\setting\configs\seller\KtbcpConfig 模型的配置类
*/
class KtbcpConfig{

    /**
    * @return array
    * 获取搜索表单配置
    */
    public static function getSearchConfig(){
    return [
            [
                "component" => "FormInput",
                "field" => "name",
                "label" => "产品名称",
                "placeholder" => "产品名称",
                "allowClear" => true,
            ],

    ];
    }

    /**
    * @return array
    * 获取表格的操作
    */
    public static function getTableActions(){
        return  [
        ];
    }

    /**
    * @return array
    * 获取表格行的操作
    * [] 表示要id, ["*"] 表示要一行记录,参数名record, ["id"] 指定需要的参数 ， selected_ids 表示需要所有选择的id
    * configParamsField 规定请求的时候带上数据行中的那些参数，只需要字段名
    */
    public static function getTableRowAction(){
        return [
            [
                "actionType" => "MODAL",
                "config" => [
                    "footer" => true,
                    "title" => "提交审核",
                    "alert" => [
                        "description" => "填写以下表单修改数据模型"
                    ]
                ],
                "configUri" => UrlHandler::toAction("seller/ktbcp","update"),
                "auth" => AuthChecker::doPermissionCheck("seller/ktbcp","update"),
                "configParamsField" => ["id"],
                "label" => "提交审核",
                ConfigEnum::CALLBACK => function($item,$config){
                    $sh_status = ArrayHelper::getValue($item,'sh_status');
                    $is_apply = ArrayHelper::getValue($item,'is_apply');
                    $label = EtcSellerTiktokProduct_shStatusEnum::getMsg($sh_status);
                    if($is_apply == 0){
                        if($sh_status == EtcSellerTiktokProduct_shStatusEnum::UNDO){
                            $label = $config['label'];
                        }
                        if($sh_status == EtcSellerTiktokProduct_shStatusEnum::REFUSE){
                            $label = "重新提交";
                        }
                    }
                    return [
                        'label' =>  $config['label'],
                        'new_label' => $label,
                        'show' => true,
                    ];
                }
            ],
        ];
    }

    /**
    * @return array
    * 获取表格配置
    */
    public static function getTableConfig(){
        return [
            "rowKey" => "id",
            "columns" => [
                [
                    "title" => "产品名称",
                    "dataIndex" => "name",
                    "sorter" => true,
                    "key" => "name",
                    "format" => "raw",
                ],
                [
                    "title" => "状态",
                    "dataIndex" => "sh_status",
                    "sorter" => true,
                    "key" => "sh_status",
                    "format" => "raw",
                ],
                [
                    "title" => "驳回原因",
                    "dataIndex" => "refuse_mark",
                    "sorter" => true,
                    "key" => "refuse_mark",
                    "format" => "raw",
                ],
                [
                    "title" => "价格",
                    "dataIndex" => "price",
                    "sorter" => true,
                    "key" => "price",
                    "format" => "text",
                ],
                [
                    "title" => "达人佣金比例",
                    "dataIndex" => "creator_commission_percent",
                    "sorter" => true,
                    "key" => "creator_commission_percent",
                    "format" => "text",
                ],
                [
                    "title" => "商家提供的佣金比例",
                    "dataIndex" => "seller_commission_percent",
                    "sorter" => true,
                    "key" => "seller_commission_percent",
                    "format" => "text",
                ],
                [
                    "title" => "星级",
                    "dataIndex" => "product_rating",
                    "sorter" => true,
                    "key" => "product_rating",
                    "format" => "text",
                ],
                [
                    "title" => "评论",
                    "dataIndex" => "product_review_count",
                    "sorter" => true,
                    "key" => "product_review_count",
                    "format" => "text",
                ],
                [
                    "title" => "出售数",
                    "dataIndex" => "product_sales",
                    "sorter" => true,
                    "key" => "product_sales",
                    "format" => "text",
                ],
                [
                    "title" => "tk店铺编号",
                    "dataIndex" => "shop_code",
                    "sorter" => true,
                    "key" => "shop_code",
                    "format" => "text",
                ],
                [
                    "title" => "样品数量",
                    "dataIndex" => "sample_quota",
                    "sorter" => true,
                    "key" => "sample_quota",
                    "format" => "text",
                ],
                [
                    "title" => "链接",
                    "dataIndex" => "link",
                    "sorter" => true,
                    "key" => "link",
                    "format" => "text",
                ],
                [
                    "title" => "产品链接",
                    "dataIndex" => "product_link",
                    "sorter" => true,
                    "key" => "product_link",
                    "format" => "text",
                ],
                [
                    "title" => "产品卖点",
                    "dataIndex" => "seller_info",
                    "sorter" => true,
                    "key" => "seller_info",
                    "format" => "text",
                ],
                [
                    "title" => "使用场景",
                    "dataIndex" => "use_info",
                    "sorter" => true,
                    "key" => "use_info",
                    "format" => "text",
                ],
                [
                    "title" => "爆款视频链接，换行",
                    "dataIndex" => "video_info",
                    "sorter" => true,
                    "key" => "video_info",
                    "format" => "text",
                ],
            ],
            "actions" => self::getTableRowAction()
        ];
    }

    /**
    * 首页配置
    */
    public static function configIndex(){
        return [
            //搜索表单配置
            "searchConfig" => self::getSearchConfig(),
            // 操作配置 configParams 规定请求的时候带上那些参数
            "actionDivConfig" => self::getTableActions(),
            //表格配置
            "tableConfig" => self::getTableConfig(),
        ];
    }




    /**
    * @param ActiveRecord $model
    * @return array
    * 修改-表单配置
    */
    public static function configUpdate(ActiveRecord $model){
        $config = [
        ];
        if($model->sh_status == EtcSellerTiktokProduct_shStatusEnum::REFUSE){
            $config = ArrayHelper::merge($config,[
                [
                    "component" => FormEnum::FormText,
                    "field" => "refuse_mark",
                    "placeholder" => "驳回原因",
                    "allowClear" => true,
                    "label" => "驳回原因",
                    "initialValue" => $model->refuse_mark,
                    "rules" => [

                    ],
                ],
            ]);
        }
        $config = ArrayHelper::merge($config,[
            [
                "component" => FormEnum::FormMulInput,
                "field" => "seller_info",
                "label" => "产品卖点",
                "placeholder" => "产品卖点",
                "allowClear" => true,
                "initialValue" => $model->seller_info,
                "rules" => [
                    [
                        'required' => true,
                        "message" => "请输入产品卖点"
                    ]
                ],
            ],
            [
                "component" => FormEnum::FormMulInput,
                "field" => "use_info",
                "label" => "使用场景",
                "placeholder" => "使用场景",
                "allowClear" => true,
                "initialValue" => $model->use_info,
                "rules" => [
                    [
                        'required' => true,
                        "message" => "请输入使用场景"
                    ]
                ],
            ],
            [
                "component" => FormEnum::FormMulInput,
                "field" => "video_info",
                "label" => "爆款视频链接，换行",
                "placeholder" => "爆款视频链接，换行",
                "allowClear" => true,
                "initialValue" => $model->video_info,
                "rules" => [
                    [
                        'required' => true,
                        "message" => "请输入使用场景"
                    ]
                ],
            ],
        ]);
        return [
            "type" => "FORM",
            "formSubmitUri" => UrlHandler::toAction("seller/ktbcp","update",["id" => $model->id]),
            "config" => $config,
        ];
    }


}

